package com.goods.controller.business;

import com.goods.business.service.HealthService;
import com.goods.common.error.SystemException;
import com.goods.common.model.system.User;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.HealthVO;
import com.goods.common.vo.system.UserInfoVO;
import com.goods.system.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/business/health")
public class HealthController {

    @Resource
    private HealthService healthService;
    @Resource
    private UserService userService;

    //查询今日是否打卡
    @GetMapping("/isReport")
    public ResponseBean isReport() throws SystemException {
        UserInfoVO info = userService.info();
        User user = userService.findUserByName(info.getUsername());
        HealthVO healthVO = healthService.isReport(user.getId());
        return ResponseBean.success(healthVO);
    }


    //添加打卡记录
    @PostMapping("/report")
    public ResponseBean report(@RequestBody HealthVO healthVO) throws SystemException {
        UserInfoVO info = userService.info();
        User user = userService.findUserByName(info.getUsername());
        Long userId = user.getId();
        healthService.report(healthVO,userId);
        return ResponseBean.success();
    }

    @GetMapping("/history")
    public ResponseBean history(Integer pageNum, Integer pageSize) throws SystemException {
        UserInfoVO info = userService.info();
        User user = userService.findUserByName(info.getUsername());
        Long userId = user.getId();
        Map map = healthService.history(pageNum,pageSize,userId);
        return ResponseBean.success(map);
    }


}
